/**
 * 
 */
package com.android.hw.projectmenu;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.text.TextUtils;
import android.util.Log;
import android.os.SystemProperties;
/**
 * @author gaoshengpan
 *
 */
public class ShowAudioInfo extends PreferenceActivity {
	private static final String KEY_BOARD = "board";
	private static final String KEY_PROJECT_NAME = "project_name";
	private static final String KEY_DATE = "date";
    private static String mUnknown = "null";
    private String TAG = "ShowAudioInfo";
	/**
	 * 
	 */
	public ShowAudioInfo() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.audio_info);
    }

	 private void setAudioInfo() {
	       String info = "";
	       String[] items = new String[4];
	       info = readFile("system/etc/audio_conf.txt");
	       if(info !=null &&  !"".equals(info)){
	    	   items = info.split(" ");
	    	   Log.d(TAG, "info---->"+info);
	    	   Log.d(TAG, "info1---->"+items[1]+"\n"+"info2---->"+items[2]+"\n"+"info3---->"+items[3]+"\n");
	    	   setSummaryText(KEY_BOARD, items[1]);
		       setSummaryText(KEY_PROJECT_NAME, items[2]);
		       setSummaryText(KEY_DATE, items[3]);
	       }
			
	    }
	 
	 private static String getSystemproString(String property) {
	        return SystemProperties.get(property, "unknown");
	    }
	 
	 /* (non-Javadoc)
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		setAudioInfo();
	}
	
	private void setSummaryText(String preferenceKey, String value) {
        Preference preference = findPreference(preferenceKey);
        if (preference == null)
            return;

        if (TextUtils.isEmpty(value))
            preference.setSummary(mUnknown);
        else
            preference.setSummary(value);
    }
	
	public static String readFile(String filePath) {
		String res = "";
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					new FileInputStream(new File(filePath))));
			String str = null;
			while ((str = br.readLine()) != null) {
				res += str;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}
}
